<template>
	<gracePage :customHeader="false">
		<view slot="gBody">
			<view class="grace-flex-center" style="width: 750rpx;margin-top: 40rpx;">
				<!-- 上传身份证正面 -->
				<view @tap="getIDCard()">
					<image :src=" id_card_img|| img_id !== '' ? id_card_img : '../../static/shenfenzheng.png'" style=" width: 330rpx;height: 210rpx;border-radius: 10rpx;"></image>
				</view>
				<!-- 上传身份证反面 -->
				<view style="margin-left: 41rpx;" @tap="getIDback">
					<image :src=" idcard_back ? idcard_back : '../../static/shenfenzhengs.png'" style=" width: 330rpx;height: 210rpx;border-radius: 10rpx;"></image>
				</view>
			</view>

			<view class="grace-rows grace-flex-center" style="margin-top: 25rpx;">
				<image src="../../static/xiangji.png" style="width: 40rpx;height: 40rpx;"></image>
				<text style="margin-left: 20rpx; font-size:23rpx;font-weight:400;color:rgba(51,51,51,1);">{{ xiangjishuoming }}</text>
			</view>

			<view style="margin-top: 35rpx;">
				<view class="grace-rows grace-flex-vcenter" style="width:750rpx;height:100rpx;background:rgba(255,255,255,1);">
					<text style="margin-left: 35rpx; font-size:30rpx;font-weight:400;color:rgba(51,51,51,1);">真实姓名：</text>
					<input placeholder="请输入您的真实姓名" v-model="user_name" style="margin-left: 60rpx;" />
				</view>

				<view class="grace-rows grace-flex-vcenter" style="margin-top: 2rpx; width:750rpx;height:100rpx;background:rgba(255,255,255,1);">
					<text style="margin-left: 35rpx; font-size:30rpx;font-weight:400;color:rgba(51,51,51,1);">身份证号：</text>
					<input placeholder="请输入您的真实姓名" v-model="user_id" style="margin-left: 60rpx;" />
				</view>
			</view>
			<view>
				<button @tap="submit" :style="{background:button_color}"
				class="button_color">确认修改</button>
			</view>
		</view>
	</gracePage>
</template>

<script>
	import gracePage from "../../graceUI/components/gracePage.vue";
	// #ifdef APP-PLUS
	const card = uni.requireNativePlugin('DC-CardRecognize');
	// #endif

	export default {
		data() {
			return {
				button_color:'',//按钮颜色
				user_name: '',
				identity: '',
				user_id: '',
				img_id: '', //身份证正面id
				back_id: '', //身份证反面id
				id_card_img: '', //身份证正面图片
				idcard_back: '', //身份证反面图片
				xiangjishuoming: '请点击卡片上传图片',
				pamd: '', // 判断上一个跳转的页面
			}
		},
		onShow() {
			this.cation()
		},
		onLoad() {
		},
		methods: {
			// 获取认证信息详情
			cation(){
				var vm = this
				this.myPost(
					'api/userapi/get_real_name',{},function(res){
						console.log(res);
						if(res.code == 200){
							if(vm.id_card_img==''){
								vm.id_card_img = res.data.id_z_img
							}
							if(vm.idcard_back==''){
								vm.idcard_back = res.data.id_f_img
							}
							vm.user_name = res.data.name
							vm.user_id = res.data.id_num
						}
					}
				)
			},
			// 上传身份证正面
			getIDCard() {
				var vm = this
				this.UpFile('api/publicapi/upfile',function(res){
					console.log(res);
					if(res.code == 200){
						vm.id_card_img = res.data.quan_path;
						vm.img_id = res.data.id;
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
						vm.cation;
					}
				},{width:330})
				
			},
			// 上传身份证反面
			getIDback() {
				var vm = this;
					this.UpFile('api/publicapi/upfile',function(res){
						console.log(res);
						if(res.code == 200){
							vm.idcard_back = res.data.quan_path;
							vm.back_id = res.data.id;
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
							vm.cation;
						}
					},{width:330})
				
			},
			// 确认修改
			submit() {
				var vm = this;
				if (this.user_name != '' && this.user_id != '') {
					console.log({
						u_name: this.user_name,
						u_identity: this.user_id,
						idcard_img: this.img_id,
						idcard_back: this.back_id
					});
					this.myPost(
						'api/userapi/name_authentication', {
							name: this.user_name,
							id_num: this.user_id,
							id_z_img: this.img_id,
							id_f_img: this.back_id
						},
						function(res) {
							console.log(res);
							if (res.code == 200) {
								uni.showToast({
									title: res.msg,
									icon: 'none'
								})
								if (vm.pamd !== 1) {
									setTimeout(function() {
										uni.redirectTo({
											url:'/pages/personal_center/real_name'
										})
									}, 500)
								} else {
									setTimeout(function() {
										uni.navigateBack()
									}, 500)

								}
							} else {
								uni.showToast({
									title: res.msg,
									icon: 'none'
								})
							}
						}
					)
				} else {
					uni.showToast({
						title:'请填写完整信息',
						icon: 'none'
					})
				}
			}
		},
		onLoad: function() {
			// #ifdef APP-PLUS
			this.xiangjishuoming = '请点击卡片上传图片'
			// #endif
		},
		onShow() {
			this.button_color = uni.getStorageSync('button_color');
		},
		components: {
			gracePage
		}
	}
</script>

<style>
	.button_color{
		margin-top: 70rpx; width:500rpx;height:90rpx;background:#3187D5;box-shadow:0px 2rpx 5rpx 0px rgba(67,67,67,0.3);border-radius:20rpx;font-size:32rpx;font-weight:400;color:rgba(255,255,255,1);
	}
</style>
